import { ProColumns, ProTable } from '@ant-design/pro-components';
import '@umijs/max';
import { Modal } from 'antd';
import React, {useEffect, useRef} from 'react';
import {ProFormInstance} from "@ant-design/pro-form/lib";

export type FormValueType = {
    target?: string;
    template?: string;
    type?: string;
    time?: string;
    frequency?: string;
} & Partial<API.InterfaceInfo>;

export type createProps = {
    columns: ProColumns<API.InterfaceInfo>[];
    onCancel: () => void;
    onSubmit: (value: API.InterfaceInfo) => Promise<void>;
    updateModalOpen: boolean;
    currentRow:ProColumns<API.InterfaceInfo>
};
const UpdateModal: React.FC<createProps> = (props) => {
    const { columns, updateModalOpen, onCancel, onSubmit,currentRow } = props; //结构赋值语法
    const formRef = useRef<ProFormInstance>();
    useEffect(()=>{
      formRef?.current?.setFieldsValue(currentRow)
    },[currentRow ])
    return (
        <Modal open={updateModalOpen} footer={null} onCancel={()=>onCancel()}>
            <ProTable
                type="form"
                columns={columns}
                formRef={formRef}
                onSubmit={async (value) => {
                    onSubmit(value);
                }}

            ></ProTable>
        </Modal>
    );
};
export default UpdateModal;
